package edu.scdx.dao;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import edu.scdx.entity.Cart;
import edu.scdx.entity.Order;

@Repository
public interface OrderMapper {

	
	@Select("insert into `order`(tel,id,name,type,author,publisher,description,price,kou,state,comment) values(#{tel},#{id},"
			+ "#{name},#{type},#{author},#{publisher},#{description},#{price},#{kou},#{state},#{comment})")
	void addOrder(@Param("tel")String userTel,@Param("id") int id, @Param("name") String name, @Param("type")String type, 
			@Param("author")String author,@Param("publisher") String publisher,
			@Param("description") String description,@Param("price") double price, 
			@Param("kou")double kou,@Param("state")Integer state,@Param("comment")Integer comment);

	
	@Select("select * from `order` where tel=#{tel} and state=#{state}")
	List<Order> getOrderByState(@Param("tel")String userTel,@Param("state") Integer state);


	@Select("select * from `order` where tel=#{tel} and comment=#{comment}")
	List<Order> getOrderByComment(@Param("tel")String userTel,@Param("comment") Integer comment);


	
	@Select("delete from `order` where tel=#{tel} and id=#{id} limit 1")
	void deleteOrder(@Param("tel")String userTel, @Param("id")Integer id);


	@Select("update `order` set comment=#{comment} where tel=#{tel} and id=#{id} limit 1")
	void updateComment(@Param("tel")String userTel,@Param("id") Integer id, @Param("comment")Integer add);


	@Select("select * from `order` where state=#{state}")
	List<Order> getAllNotSold(@Param("state")Integer state);

	@Select("update `order` set state=#{state} where tel=#{tel} and id=#{id} limit 1")
	void updateState(@Param("tel")String tel,@Param("id") Integer id,@Param("state") Integer state);
	
	

}
